
public class exercise9_9 {
    private int n = 3;
    private double side = 1;
    private double x = 0;
    private double y = 0;

    public exercise9_9() { }
    public exercise9_9(int n, double side) {
        this.n = n;
        this.side = side;
    }
    public exercise9_9(int n, double side, double x, double y) {
        this(n, side);
        this.x = x;
        this.y = y;
    }

    public int getN() { return n; }
    public void setN(int n) { this.n = n; }
    public double getSide() { return side; }
    public void setSide(double side) { this.side = side; }
    public double getX() { return x; }
    public void setX(double x) { this.x = x; }
    public double getY() { return y; }
    public void setY(double y) { this.y = y; }

    public double getPerimeter() {
        return n * side;
    }

    public double getArea() {
        return n * side * side / (4 * Math.tan(Math.PI / n));
    }

    @Override
    public String toString() {
        return String.format("RegularPolygon[n=%d, side=%.2f, center=(%.2f,%.2f)]", n, side, x, y);
    }

    public static void main(String[] args) {
        exercise9_9 p1 = new exercise9_9();
        exercise9_9 p2 = new exercise9_9(6, 4);
        exercise9_9 p3 = new exercise9_9(10, 4, 5.6, 7.8);

        System.out.println(p1 + " 周长=" + p1.getPerimeter() + " 面积=" + p1.getArea());
        System.out.println(p2 + " 周长=" + p2.getPerimeter() + " 面积=" + p2.getArea());
        System.out.println(p3 + " 周长=" + p3.getPerimeter() + " 面积=" + p3.getArea());
    }
}